/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 012. 左右两边子数组的和相等
 * @author: WXY
 * @create: 2022-12-21 14:56
 * @Version 1.0
 **/

public class offer_four3_pivotIndex {
    public static int pivotIndex(int[] nums) {
        int sum = 0,cur = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            sum -= nums[i];
            if (sum == cur) return i;
            cur += nums[i];
        }
        return  -1;
    }
}
